/** 
  成绩录入
*/
<template>
  <div class="score-entry-container">
    <div style="height: 40px;">
      <el-breadcrumb separator="/" class="float-left" style="padding-top: 8px;">
        <el-breadcrumb-item :to="{ path: '/scoreEntryMana' }">
          <span @click="backToMain()">{{ $t('scoreEntryMana.scoreEntry') }}</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t('scoreMangementBase.details') }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="float-right">
        <el-button type="text" @click="back()">{{ $t('common.btn.back') }}</el-button>
      </div>
    </div>
    <el-steps
      :space="200"
      :active="active"
      :align-center="true"
      finish-status="success"
      process-status="finish">
      <el-step align-center="true" :title="$t('scoreEntryMana.gradeComposition')">
      </el-step>
      <el-step align-center="true" :title="$t('scoreEntryMana.scoreEntry')"></el-step>
    </el-steps>
    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
      <!-- 成绩构成开始 -->
      <template v-if="active === 0">
        <span style="font-size: 18px;">{{ $t('scoreEntryMana.basicInfo') }}</span>
        <span style="float: right; padding: 3px 0">{{ $t('scoreEntryMana.lastEntry') }}：{{ basicInfo.lastImporter }}{{ basicInfo.lastImporterTime }}</span>
        <el-divider></el-divider>
        <div style="height: 130px;">
          <el-row class="blank-sub-title">
            <!-- 课程代码 -->
            <el-col :span="8">
              {{ $t('scoreEntryMana.courseCode') }}：{{ detailInfo.condition.courseCode }}
            </el-col>
            <!-- 课程名称 -->
            <el-col :span="8">
              {{ $t('scoreEntryMana.courseName') }}：{{ detailInfo.condition.courseName }}
            </el-col>
            <!-- 课程序号 -->
            <el-col :span="8">
              {{ $t('scoreEntryMana.courseNum') }}：{{ detailInfo.condition.courseNo }}
            </el-col>
          </el-row>
          <el-row class="blank-sub-title">
            <!-- 允许录入 -->
            <el-col :span="24">
              {{ $t('scoreEntryMana.admitToEntry') }}：{{ basicInfo.toScoreStructure }}
            </el-col>
          </el-row>
          <el-row class="blank-sub-title">
            <!-- 开始时间 -->
            <el-col :span="8">
              {{ $t('scoreEntrySwitch.startTime') }}：{{ getTime(basicInfo.courseEntryStartTime) }}
            </el-col>
            <!-- 结束时间 -->
            <el-col :span="8">
              {{ $t('scoreEntrySwitch.endTime') }}：{{ getTime(basicInfo.courseEntryStopTime) }}
            </el-col>
          </el-row>
        </div>
        <div style="font-size: 18px;">{{ $t('scoreEntryMana.gradeComposition') }}</div>
        <el-divider></el-divider>
        <el-form :model="scoreStructure" ref="scoreStructure" label-position="left">
          <!-- 平时成绩1 改为 过程性考核1 -->
          <el-row style="" v-if="scoreStructure.showDailyScore1">
            <span style="float: left;width: 30px;line-height: 30px;">
              <el-checkbox v-model="scoreStructure.dailyScore1Checked" :disabled="scoreStructure.disabledCheck" @change="(value) => checkScore(value, '11005')"></el-checkbox>
            </span>
            <el-col :span="6">
              <el-form-item
                prop="dailyScore1Proportion"
                label-width="120px"
                ref="dailyScore1Proportion"
                :label="scoreStructureNames.dailyScore1 + '：'"
                :rules="[{ required: scoreStructure.dailyScore1Checked, message: scoreStructureNames.dailyScore1 + $t('scoreMangementBase.notBlank'), trigger: 'blur' }, { validator: validateProportion, trigger: 'blur'}]">
                <!-- <el-input style="width: 150px;" :disabled="!scoreStructure.dailyScore1Checked || scoreStructure.disabledCheck" type="number" v-model="scoreStructure.dailyScore1Proportion" min="1" max="100" clearable>
                  <template slot="append">%</template>
                </el-input> -->
                <el-input style="width: 150px;" type="number" v-model="scoreStructure.dailyScore1Proportion" min="1" max="100" clearable>
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
            </el-col>
            <!-- 成绩记录方式 -->
            <el-col :span="6">
              <el-form-item
                prop="dailyScore1RecordType" 
                :label="$t('gradeRelatedSetting.gradeRecordMethod') + '：'">
                <el-select v-model="scoreStructure.dailyScore1RecordType" :disabled="!scoreStructure.dailyScore1Checked || scoreStructure.disabledCheck" :placeholder="$t('common.pla.pleaseSelect')" >
                  <el-option
                    v-for="item in options.recordTypeList"
                    :key="item.key"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 平时成绩2 改为 过程性考核2 -->
          <el-row style="" v-if="scoreStructure.showDailyScore2">
            <span style="float: left;width: 30px;line-height: 30px;">
              <el-checkbox v-model="scoreStructure.dailyScore2Checked" :disabled="scoreStructure.disabledCheck" @change="(value) => checkScore(value, '11006')"></el-checkbox>
            </span>
            <el-col :span="6">
              <el-form-item
                ref="dailyScore2Proportion"
                prop="dailyScore2Proportion"
                label-width="120px" 
                :label="scoreStructureNames.dailyScore2 + '：'"
                :rules="[{ required: scoreStructure.dailyScore2Checked, message: scoreStructureNames.dailyScore2 + $t('scoreMangementBase.notBlank'), trigger: 'blur' }, { validator: validateProportion, trigger: 'blur'}]">
                <!-- <el-input style="width: 150px;" :disabled="!scoreStructure.dailyScore2Checked || scoreStructure.disabledCheck" type="number" v-model="scoreStructure.dailyScore2Proportion" min="0" max="100" clearable>
                  <template slot="append">%</template>
                </el-input> -->
                <el-input style="width: 150px;" type="number" v-model="scoreStructure.dailyScore2Proportion" min="0" max="100" clearable>
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
            </el-col>
            <!-- 成绩记录方式 -->
            <el-col :span="6">
              <el-form-item
                prop="dailyScore2RecordType" 
                :label="$t('gradeRelatedSetting.gradeRecordMethod') + '：'">
                <el-select v-model="scoreStructure.dailyScore2RecordType" :disabled="!scoreStructure.dailyScore2Checked || scoreStructure.disabledCheck" :placeholder="$t('common.pla.pleaseSelect')" >
                  <el-option
                    v-for="item in options.recordTypeList"
                    :key="item.key"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 期中成绩 改为 考勤 -->
          <el-row style="" v-if="scoreStructure.showMidtermScore">
            <span style="float: left;width: 30px;line-height: 30px;">
              <el-checkbox v-model="scoreStructure.midtermScoreChecked" :disabled="scoreStructure.disabledCheck" @change="(value) => checkScore(value, '11007')"></el-checkbox>
            </span>
            <el-col :span="6">
              <el-form-item
                ref="midtermScoreProportion"
                prop="midtermScoreProportion"
                label-width="120px"
                :label="scoreStructureNames.midtermScore + '：'"
                :rules="[{ required: scoreStructure.midtermScoreChecked, message: scoreStructureNames.midtermScore + $t('scoreMangementBase.notBlank'), trigger: 'blur' }, { validator: validateProportion, trigger: 'blur'}]">
                <!-- <el-input style="width: 150px;" :disabled="!scoreStructure.midtermScoreChecked || scoreStructure.disabledCheck" type="number" v-model="scoreStructure.midtermScoreProportion" min="0" max="100" clearable>
                  <template slot="append">%</template>
                </el-input> -->
                <el-input style="width: 150px;" type="number" v-model="scoreStructure.midtermScoreProportion" min="0" max="100" clearable>
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
            </el-col>
            <!-- 成绩记录方式 -->
            <el-col :span="6">
              <el-form-item
                prop="midtermScoreRecordType" 
                :label="$t('gradeRelatedSetting.gradeRecordMethod') + '：'">
                <el-select v-model="scoreStructure.midtermScoreRecordType" :disabled="!scoreStructure.midtermScoreChecked || scoreStructure.disabledCheck" :placeholder="$t('common.pla.pleaseSelect')" >
                  <el-option
                    v-for="item in options.recordTypeList"
                    :key="item.key"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 总评成绩：期末成绩一定要设置 -->
          <el-row style="" v-if="detailInfo.condition.examType === '2'">
            <span style="float: left;width: 30px;line-height: 30px;">
              <el-checkbox v-model="scoreStructure.finalScoreChecked" :disabled="scoreStructure.disabledCheck" @change="(value) => checkScore(value, '11008')"></el-checkbox>
            </span>
            <el-col :span="6">
              <el-form-item
                ref="finalScoreProportion"
                prop="finalScoreProportion"
                label-width="120px" 
                :label="scoreStructureNames.finalScore + '：'"
                :rules="[{ required: true, message: scoreStructureNames.finalScore + $t('scoreMangementBase.notBlank'), trigger: 'blur' }, { validator: validateProportion, trigger: 'blur'}]">
                <!-- <el-input style="width: 150px;" :disabled="!scoreStructure.finalScoreChecked || scoreStructure.disabledCheck" type="number" v-model="scoreStructure.finalScoreProportion" min="0" max="100" clearable>
                  <template slot="append">%</template>
                </el-input> -->
                 <el-input style="width: 150px;" type="number" v-model="scoreStructure.finalScoreProportion" min="0" max="100" clearable>
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
            </el-col>
            <!-- 成绩记录方式 -->
            <el-col :span="6">
              <el-form-item
                prop="finalScoreRecordType" 
                :label="$t('gradeRelatedSetting.gradeRecordMethod') + '：'">
                <el-select v-model="scoreStructure.finalScoreRecordType" :disabled="!scoreStructure.finalScoreChecked || scoreStructure.disabledCheck" :placeholder="$t('common.pla.pleaseSelect')" >
                  <el-option
                    v-for="item in options.recordTypeList"
                    :key="item.key"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 重考成绩 -->
          <el-row style="" v-if="scoreStructure.showRetakeScore">
            <!-- 成绩记录方式 -->
            <el-col :span="6">
              <el-form-item
                prop="retakeScoreRecordType" 
                :label="scoreStructureNames.retakeScore + '：'">
                <el-select v-model="scoreStructure.retakeScoreRecordType" :disabled="true" :placeholder="$t('common.pla.pleaseSelect')" >
                  <el-option
                    v-for="item in options.recordTypeList"
                    :key="item.key"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 缓考成绩 -->
          <el-row style="" v-if="scoreStructure.showSlowScore">
            <!-- 成绩记录方式 -->
            <el-col :span="6">
              <el-form-item
                prop="slowScoreRecordType" 
                :label="scoreStructureNames.slowScore + '：'">
                <el-select v-model="scoreStructure.slowScoreRecordType" :disabled="true" :placeholder="$t('common.pla.pleaseSelect')" >
                  <el-option
                    v-for="item in options.recordTypeList"
                    :key="item.key"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div style="width: 100%;text-align: right;">
          <el-button @click="back()">{{ $t('scoreMangementBase.back') }}</el-button>
          <el-button v-if="detailInfo.condition.examType === '2'" @click="save()">{{ $t('scoreMangementBase.save') }}</el-button>
          <el-button type="primary" @click="nextStep()">{{ $t('scoreMangementBase.nextStep') }}</el-button>
        </div>
      </template>
      <!-- 成绩构成结束 -->
      <!-- 成绩录入开始 -->
      <template v-if="active === 1">
        <score-entry-table :detailInfo="detailInfo" @get-prev-step="turnToPrevStep" @turn-to-main-page="turnToMainPage"></score-entry-table>
      </template>
      <!-- 成绩录入结束 -->
    </el-card>
  </div>
</template>
<script>
import scoreManagementApi from 'common/src/api/scoreManagement/scoreManagement';
import scoreEntryTable from './scoreEntryTable';
import * as INDEX from 'common/src/utils/index';
import UTILS from "common/src/utils/utils";
import { queryDic } from "common/src/api/dictionary";

export default {
  components: {
    'score-entry-table': scoreEntryTable
  },
  data () {
    return {
      active: 0,
      basicInfo: {
        "calendarId": "",
        "calendarName": null,
        "teachingClassId": "",
        "courseCode": "",
        "courseName": "",
        "courseNameEn": "",
        "courseNo": "",
        "faculty": "",
        "teacher": "",
        "teacherCode": "",
        "scoreStructure": "",
        "toScoreStructure": "",
        "elcNumber": null,
        "minorScoreStructureBean": {},
        "studentList": null,
        "lastImporter": "",
        "lastImporterTime": "",
        "isWhite": null,
        "releaseAllType": null,
        "courseLabel": "",
        "facultyCode": null,
        "courseEntryStartTime": null,
        "courseEntryStopTime": null,
        "minorScoreStructure": {}
      },
      options: {
        recordTypeList: [],
        totalGradeList: []
      },
      finalScoreList: [],
      scoreStructureNames: {
        dailyScore1: '', // 平时成绩1 改为 过程性考核1
        dailyScore2: '', // 平时成绩2 改为 过程性考核2
        midtermScore: '', // 期中成绩 改为 考勤
        finalScore: '', // 期末成绩
        retakeScore: '', // 重考成绩
        slowScore: '' // 缓考成绩
      },
      scoreStructure: {
        disabledCheck: false, // 勾选禁用
        showDailyScore1: false, // 包含平时成绩1
        showDailyScore2: false, // 包含平时成绩2
        showMidtermScore: false, // 包含期中成绩
        showFinalScore: false, // 包含期末成绩
        showRetakeScore: false, // 包含重考成绩
        showSlowScore: false, // 包含缓考成绩
        dailyScore1Checked: false, // 平时成绩1构成
        dailyScore2Checked: false, // 平时成绩2构成
        midtermScoreChecked: false, // 期中成绩构成
        finalScoreChecked: false, // 期末成绩构成
        retakeScoreChecked: false, // 重考构成
        slowScoreChecked: false, // 缓考构成
        dailyScore1Proportion: '', // 平时成绩1占比
        dailyScore2Proportion: '', // 平时成绩2占比
        midtermScoreProportion: '', // 期中成绩占比
        finalScoreProportion: '', // 期末成绩占比
        retakeScoreProportion: '', // 重考成绩占比
        slowScoreProportion: '', // 缓考成绩占比
        dailyScore1RecordType: '1001', // 平时成绩1记录方式
        dailyScore2RecordType: '1001', // 平时成绩记录方式
        midtermScoreRecordType: '1001', // 期中成绩记录方式
        finalScoreRecordType: '1001', // 期末成绩记录方式
        retakeScoreRecordType: '1001', // 重考成绩记录方式
        slowScoreRecordType: '1001' // 缓考成绩记录方式
      }
    }
  },
  props: {
    detailInfo: {
      type: Object,
      default: () => {}
    },
    admitToEntryType: {
      type: String,
      default: ''
    }
  },
  created() {
  },
  async mounted() {
    await this.initOptions()
    if (this.detailInfo.condition.examType === '1') {
      await this.getLastTermFinalScoreRecord()
    }
    this.dealWithData()
    
  },
  methods: {
    // 校验占比，只能输入正整数
    validateProportion(rule, value, callback) {
      // let expReg = /^[1-9][0-9]{1,3}$/
      let expReg = /^((?!0)\d{1,2}|100)$/
      if (!value) {
        callback()
      } if (Number(value) > 100) {
        callback(new Error(this.$t('gradeRelatedSetting.lessThanMax')))
      } else if (!expReg.test(value)) {
        callback(new Error(this.$t('scoreMangementBase.validateProportion')))
      } else {
        callback()
      }
    },
    // 获取时间
    getTime(timeStamp) {
      return INDEX.parseTime(new Date(timeStamp), '{y}/{m}/{d} {h}:{i}:{s}')
    },
    async initOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: [
          "X_ZPCJCF_FX", // 总评成绩成分
          "X_CJJL_FX" // 成绩记录方式
        ]
      }
      const resp = await queryDic(data)
      if (resp.code === 200) {
        UTILS.fillSelect(
          {
            totalGradeList: "X_ZPCJCF_FX", // 总评成绩成分
            recordTypeList: "X_CJJL_FX" // 成绩记录方式
          },
          resp.data,
          this.options
        )
        this.scoreStructureNames.dailyScore1 = resp.data['X_ZPCJCF_FX']['11005'] // 平时成绩1 改为 过程性考核1
        this.scoreStructureNames.dailyScore2 = resp.data['X_ZPCJCF_FX']['11006'] // 平时成绩2 改为 过程性考核2
        this.scoreStructureNames.midtermScore = resp.data['X_ZPCJCF_FX']['11007'] // 期中成绩 改为 考勤
        this.scoreStructureNames.finalScore = resp.data['X_ZPCJCF_FX']['11008'] // 期末成绩
        this.scoreStructureNames.slowScore = resp.data['X_ZPCJCF_FX']['11003'] // 缓考成绩
        this.scoreStructureNames.retakeScore = resp.data['X_ZPCJCF_FX']['11004'] // 重考成绩
        // 课程成绩管理--总评
        if (this.detailInfo.condition.examType === '2') {
          this.options.totalGradeList = this.options.totalGradeList.filter(value => {
            return value.value === '11005' || value.value === '11006' || value.value === '11007' || value.value === '11008'
          })
        }
        // 重缓考成绩管理--重缓考
        if (this.detailInfo.condition.examType === '1') {
          this.options.totalGradeList = this.options.totalGradeList.filter(value => {
            return value.value === '11003' || value.value === '11004'
          })
        }
      }
    },
    // 获取上一学期期末的成绩记录方式
    async getLastTermFinalScoreRecord() {
      let currentParams = JSON.parse(JSON.stringify(this.detailInfo))
      currentParams.condition.calendarId = currentParams.condition.calendarId - 1
      currentParams.condition.examType = '2'
      let respInfo = await scoreManagementApi.queryScoreStucture(currentParams)
      if (respInfo.code === 200) {
        this.scoreStructure.slowScoreRecordType = respInfo.data.minorScoreStructure.finalScoreRecordType ? respInfo.data.minorScoreStructure.finalScoreRecordType : '1001'
        if (respInfo.data.minorScoreStructure) {
          // 重缓考成绩取上学期期末成绩的占比
          this.scoreStructure.retakeScoreProportion = respInfo.data.minorScoreStructure.finalScoreProportion
          this.scoreStructure.slowScoreProportion = respInfo.data.minorScoreStructure.finalScoreProportion
        }
      }
    },
    // 处理查询后的数据
    dealWithData(type) {
      scoreManagementApi.queryScoreStucture(this.detailInfo).then(res => {
        if (res.code === 200) {
          this.basicInfo = res.data
          if (this.basicInfo.minorScoreStructure && this.basicInfo.minorScoreStructure.id) {
            this.scoreStructure.disabledCheck = true
          }
          if (this.basicInfo.minorScoreStructureBean) {
            // 含平时成绩1
            if (this.basicInfo.minorScoreStructureBean.containDailyScore1) {
              this.scoreStructure.showDailyScore1 = true
              if (this.basicInfo.minorScoreStructure) {
                this.scoreStructure.dailyScore1Checked = this.basicInfo.minorScoreStructure.id && this.basicInfo.minorScoreStructure.dailyScore1Proportion > 0
                this.scoreStructure.dailyScore1Proportion = this.basicInfo.minorScoreStructure.dailyScore1Proportion
                this.scoreStructure.dailyScore1RecordType = this.basicInfo.minorScoreStructure.dailyScore1RecordType ? this.basicInfo.minorScoreStructure.dailyScore1RecordType : '1001'
              }
            }
            // 含平时成绩2
            if (this.basicInfo.minorScoreStructureBean.containDailyScore2) {
              this.scoreStructure.showDailyScore2 = true
              if (this.basicInfo.minorScoreStructure) {
                this.scoreStructure.dailyScore2Checked = this.basicInfo.minorScoreStructure.id && this.basicInfo.minorScoreStructure.dailyScore2Proportion > 0
                this.scoreStructure.dailyScore2Proportion = this.basicInfo.minorScoreStructure.dailyScore2Proportion
                this.scoreStructure.dailyScore2RecordType = this.basicInfo.minorScoreStructure.dailyScore2RecordType ? this.basicInfo.minorScoreStructure.dailyScore2RecordType : '1001'
              }
            }
            // 期中成绩
            if (this.basicInfo.minorScoreStructureBean.containMidtermScore) {
              this.scoreStructure.showMidtermScore = true
              if (this.basicInfo.minorScoreStructure) {
                this.scoreStructure.midtermScoreChecked = this.basicInfo.minorScoreStructure.id && this.basicInfo.minorScoreStructure.midtermScoreProportion > 0
                this.scoreStructure.midtermScoreProportion = this.basicInfo.minorScoreStructure.midtermScoreProportion
                this.scoreStructure.midtermScoreRecordType = this.basicInfo.minorScoreStructure.midtermScoreRecordType ? this.basicInfo.minorScoreStructure.midtermScoreRecordType : '1001'
              }
            }
            // 期末成绩
            if (this.basicInfo.minorScoreStructureBean.containFinalScore) {
              this.scoreStructure.showFinalScore = true
              this.scoreStructure.finalScoreChecked = true
              if (this.basicInfo.minorScoreStructure) {
                this.scoreStructure.finalScoreProportion = this.basicInfo.minorScoreStructure.finalScoreProportion
                this.scoreStructure.finalScoreRecordType = this.basicInfo.minorScoreStructure.finalScoreRecordType ? this.basicInfo.minorScoreStructure.finalScoreRecordType : '1001'
              }
            }
            // 含重考成绩
            if (this.basicInfo.minorScoreStructureBean.containRetakeScore) {
              this.scoreStructure.showRetakeScore = true
              this.scoreStructure.retakeScoreChecked = true
              this.scoreStructure.retakeScoreRecordType = this.basicInfo.scoreSetting.reexamInputType ? this.basicInfo.scoreSetting.reexamInputType : '1001'
            }
            // 含缓考成绩
            if (this.basicInfo.minorScoreStructureBean.containSlowScore) {
              this.scoreStructure.showSlowScore = true
              this.scoreStructure.slowScoreChecked = true
            }
          }
          if (type) {
            this.active = 0
          }
        }
      })
      
    },
    // 选择多选框
    checkScore(value, scoreTypeCode) {
      // 平时成绩1 改为 过程性考核1
      if (scoreTypeCode === '11005') {
        if (!value) {
          this.$set(this.scoreStructure, 'dailyScore1Proportion', '')
          this.$refs['dailyScore1Proportion'].clearValidate()
          this.$set(this.scoreStructure, 'dailyScore1RecordType', '1001')
        }
      }
      // 平时成绩2 改为 过程性考核2
      if (scoreTypeCode === '11006') {
        this.$set(this.scoreStructure, 'dailyScore2Proportion', '')
        this.$refs['dailyScore2Proportion'].clearValidate()
        this.$set(this.scoreStructure, 'dailyScore2RecordType', '1001')
      }
      // 期中成绩 改为 考勤
      if (scoreTypeCode === '11007') {
        this.$set(this.scoreStructure, 'midtermScoreProportion', '')
        this.$refs['midtermScoreProportion'].clearValidate()
        this.$set(this.scoreStructure, 'midtermScoreRecordType', '1001')
      }
      // 期末成绩
      if (scoreTypeCode === '11008') {
        this.$set(this.scoreStructure, 'finalScoreProportion', '')
        this.$refs['finalScoreProportion'].clearValidate()
        this.$set(this.scoreStructure, 'finalScoreRecordType', '1001')
      }
      // 重考成绩
      if (scoreTypeCode === '11004') {
        this.$set(this.scoreStructure, 'retakeScoreProportion', '')
        this.$refs['retakeScoreProportion'].clearValidate()
        this.$set(this.scoreStructure, 'retakeScoreRecordType', '1001')
      }
      // 缓考成绩
      if (scoreTypeCode === '11003') {
        this.$set(this.scoreStructure, 'slowScoreProportion', '')
        this.$refs['slowScoreProportion'].clearValidate()
        this.$set(this.scoreStructure, 'slowScoreRecordType', '1001')
      }
    },
    // 返回主页
    backToMain() {
      this.$emit('refresh-main-page')
    },
    // 获取期终成绩关联的可录入类型成绩
    async selectGlobalSetInfo() {
      let globalInfoRes = await scoreManagementApi.queryGlobalSetInfo({
        "setType": 'totalGrade'
      })
      let finalScoreList = []
      let finalCodeList = []
      if (globalInfoRes.code === 200) {
        if (globalInfoRes.data.length > 0) {
          finalScoreList = globalInfoRes.data[0].setContentCn.split(',')
          finalCodeList = globalInfoRes.data[0].setContentCode.split(',')
          if (finalScoreList.length > 0) {
            finalScoreList.forEach((value, index) => {
              this.finalScoreList.push({
                value: '',
                checked: false,
                label: value,
                recordMethod: '',
                code: finalCodeList[index]
              })
            })
          }
        }
      }
    },
    // 返回
    back() {
      this.$emit('refresh-main-page')
    },
    // 保存数据
    saveData(operatorType) {
      scoreManagementApi.saveScoreStructureInfo({
        "calendarId": this.basicInfo.calendarId,
        "teachingClassId": this.basicInfo.teachingClassId,
        "courseCode": this.basicInfo.courseCode,
        "examType": this.detailInfo.condition.examType,
        "faculty": this.basicInfo.faculty,
        "operatorType": operatorType,
        "minorScoreStructure": {
          "teachingClassId": this.basicInfo.teachingClassId,
          "retakeScoreProportion": this.scoreStructure.retakeScoreChecked ? Number(this.scoreStructure.retakeScoreProportion) : null, // 重考成绩占比
          "slowScoreProportion": this.scoreStructure.slowScoreChecked ? Number(this.scoreStructure.slowScoreProportion) : null, // 缓考成绩占比
          "dailyScore1Proportion": this.scoreStructure.dailyScore1Checked ? Number(this.scoreStructure.dailyScore1Proportion) : null, // 平时成绩1占比
          "dailyScore2Proportion": this.scoreStructure.dailyScore2Checked ? Number(this.scoreStructure.dailyScore2Proportion) : null, // 平时成绩2占比
          "midtermScoreProportion": this.scoreStructure.midtermScoreChecked ? Number(this.scoreStructure.midtermScoreProportion) : null, // 期中成绩占比
          "finalScoreProportion": this.scoreStructure.finalScoreChecked ? Number(this.scoreStructure.finalScoreProportion) : null, // 期末成绩占比
          "retakeScoreRecordType": this.scoreStructure.retakeScoreChecked ? Number(this.scoreStructure.retakeScoreRecordType) : null, // 重考成绩记录方式
          "slowScoreRecordType": this.scoreStructure.slowScoreChecked ? Number(this.scoreStructure.slowScoreRecordType) : null, // 缓考成绩记录方式
          "dailyScore1RecordType": this.scoreStructure.dailyScore1Checked ? Number(this.scoreStructure.dailyScore1RecordType) : null, // 平时成绩1记录方式
          "dailyScore2RecordType": this.scoreStructure.dailyScore2Checked ? Number(this.scoreStructure.dailyScore2RecordType) : null, // 平时成绩2记录方式
          "midtermScoreRecordType": this.scoreStructure.midtermScoreChecked ? Number(this.scoreStructure.midtermScoreRecordType) : null, // 期中成绩记录方式
          "finalScoreRecordType": this.scoreStructure.finalScoreChecked ? Number(this.scoreStructure.finalScoreRecordType) : null // 期末成绩记录方式
        }
      }).then(res => {
        if (res.code === 200) {
          this.$message.success(this.$t('scoreMangementBase.savedSuccessfully'))
          if (operatorType === '1') {
            this.dealWithData()
          } else {
            this.active = 1
          }
        }
      })
    },
    // 保存
    save() {
      this.$refs['scoreStructure'].validate(valid => {
        if (valid) {
          if (this.detailInfo.condition.examType === '2') {
            let totalScore = 0
            // 平时成绩1 改为 过程性考核1
            if (this.scoreStructure.dailyScore1Checked) {
              totalScore += Number(this.scoreStructure.dailyScore1Proportion)
            }
            // 平时成绩2 改为 过程性考核2
            if (this.scoreStructure.dailyScore2Checked) {
              totalScore += Number(this.scoreStructure.dailyScore2Proportion)
            }
            // 期中成绩 改为 考勤
            if (this.scoreStructure.midtermScoreChecked) {
              totalScore += Number(this.scoreStructure.midtermScoreProportion)
            }
            // 期末成绩
            if (this.scoreStructure.finalScoreChecked) {
              totalScore += Number(this.scoreStructure.finalScoreProportion)
            }
            // 重考成绩
            if (this.scoreStructure.retakeScoreChecked) {
              totalScore += Number(this.scoreStructure.retakeScoreProportion)
            }
            // 缓考成绩
            if (this.scoreStructure.slowScoreChecked) {
              totalScore += Number(this.scoreStructure.slowScoreProportion)
            }
            if (totalScore !== 100) {
              this.$message.error(this.$t('scoreEntryMana.validateScoreComposite'))
              return
            }
          }
          this.$confirm(this.$t('scoreEntryMana.confirmToSaveScore'), this.$t('scoreMangementBase.prompt'), {
            confirmButtonText: this.$t('scoreMangementBase.confirm'),
            cancelButtonText: this.$t('scoreMangementBase.cancel'),
            type: 'warning'
          }).then(() => {
            this.saveData("1")
          })
        }
      })
    },
    // 下一步
    nextStep() {
      if (this.detailInfo.condition.examType === '2') {
        this.$refs['scoreStructure'].validate(valid => {
          if (valid) {
            if (this.scoreStructure.disabledCheck) {
              this.saveData('2')
            } else {
              this.$confirm(this.$t('scoreEntryMana.confirmToSaveScore'), this.$t('scoreMangementBase.prompt'), {
                confirmButtonText: this.$t('scoreMangementBase.confirm'),
                cancelButtonText: this.$t('scoreMangementBase.cancel'),
                type: 'warning'
              }).then(() => {
                this.saveData('2')
              })
            }
          }
        })
      } else if (this.detailInfo.condition.examType === '1') {
        this.saveData('2')
      }
    },
    // 上一步
    turnToPrevStep() {
      this.scoreStructure.showDailyScore1 = false // 包含平时成绩1 
      this.scoreStructure.showDailyScore2 = false // 包含平时成绩2
      this.scoreStructure.showMidtermScore = false // 包含期中成绩
      this.scoreStructure.showFinalScore = false // 包含期末成绩
      this.scoreStructure.showRetakeScore = false // 包含重考成绩
      this.scoreStructure.showSlowScore = false // 包含缓考成绩
      this.dealWithData('onload')
    },
    // 回到首页
    turnToMainPage() {
      this.$emit('refresh-main-page')
    }
  }
}
</script>

<style lang="scss" scoped>
  .score-entry-container ::v-deep {
    .el-steps--horizontal {
      width: 400px;
      margin: 0 auto;
    }
    .title {
      margin-bottom: 40px;
      font-size: 18px;
    }
    .blank-sub-title {
      padding: 8px 0;
    }
    .el-divider--horizontal {
      margin: 12px 0 20px 0;
    }
  }

</style>